package com.thread.threadfirst;


import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class Te {

    Character get(String string) {
        HashMap<Character, Integer> map = new HashMap();
        for (int i = 0; i < string.length(); i++) {
            char c = string.charAt(i);
            if ('a' <= c && c <= 'z') {
                if (map.containsKey(c)) {
                    Integer num = map.get(c);
                    map.put(c, num + 1);
                } else {
                    map.put(c, 0);
                }

            }
        }
        if (map.isEmpty()) {
            return null;
        }
        int max = 0;
        char ch = ' ';
        Iterator<Map.Entry<Character, Integer>> entries = map.entrySet().iterator();
        while (entries.hasNext()) {
            Map.Entry<Character, Integer> entry = entries.next();
            Character key = entry.getKey();
            Integer value = entry.getValue();
            if (value > max) {
                max = value;
                ch = key;
            }
            if (value == max) {
                if (ch > key) {
                    ch = key;
                }
            }

        }
        return ch;
    }


    public static void main(String[] args) {
        Te t = new Te();
        Character c = t.get("dffsdafsd");
        System.out.println("&&&" + c);
    }
}
